package com.stackfarm.fvcommon.utils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.Date;
import java.util.UUID;

public class iCodeTools {
    private static void createIcode(int count) throws Exception {
        String[] icode = new String[count];
        //生成用户
        for (int i = 0; i < count; i++){
            icode[i] = String.valueOf(System.currentTimeMillis()).substring(1,3) + UUID.randomUUID().toString().substring(1, 20);
        }
        System.out.println("Begin");
        //插入数据库
        Connection conn = DBUtil.getConn();
        String sql = "INSERT INTO`icode` (data) values(?)";
        PreparedStatement pstmt = conn.prepareStatement(sql);
        for (int i = 0; i < count; i++) {
            System.out.println(icode[i]);
            pstmt.setString(1, icode[i]);
            pstmt.execute();
        }
        pstmt.close();
        conn.close();
        System.out.println("insert to db");
    }

    public static void main(String[] args) throws Exception {
        createIcode(100);
    }
}
